/*
 * Create Author  : jinpeng.chen
 * Create Date    : 2018-10-16
 * Project        : designpattern-learn
 * File Name      : TestStrategy.java
 *
 * Copyright (c) 2010-2018 by 18Birdies, LLC.
 * All Rights Reserved.
 *
 */
package com.charles.designpattern.strategy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 功能描述:  <p>
 *
 * @author : jinpeng.chen <p>
 * @version 1.0 2018-10-16
 * @since designpattern-learn 1.0
 */
@Controller
public class TestStrategy {

  @Autowired
  private MemberPriceStrategyProcessors memberPriceStrategyProcessors;

  /**
   * http://localhost:8080/testStrategy?level=INTERMEDIATE&price=10
   * http://localhost:8080/testStrategy?level=ADVANCED&price=10
   * http://localhost:8080/testStrategy?level=PRIMARY&price=10
   * @param level
   * @param price
   * @return
   */
  @RequestMapping("/testStrategy")
  @ResponseBody
  public String testStrategy(@RequestParam(value = "level") MemberLevel level, @RequestParam("price") double price) {
    MemberStrategy strategyProcessor = memberPriceStrategyProcessors.getStrategyProcessor(level);
    return String.valueOf(strategyProcessor.calPrice(price));
  }

}
